﻿using System.Collections.Generic;
using System.Text;


namespace RStudio.UIFramwork
{
    /// <summary>
    /// 栈记录
    /// </summary>
    public class UIModuleStack
    {
        public UIModuleStack()
        {
            BackStack = new Stack<UIEventArgs>();
        }


        public Stack<UIEventArgs> BackStack { get; private set; }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="uiEvent"></param>
        public void Push(UIEventArgs uiEvent)
        {
            this.BackStack.Push(uiEvent);
            //DebugStack();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="output"></param>
        /// <returns></returns>
        public bool Pop(out UIEventArgs output)
        {
            output = null;

            if (this.BackStack == null) return false;
            if (this.BackStack.Count == 0) return false;
            
            return this.BackStack.TryPop(out output);
        }

        public bool Peek(out UIEventArgs output)
        {
            output  =null;

            if (this.BackStack == null) return false;
            if (this.BackStack.Count == 0) return false;

            return this.BackStack.TryPeek(out output);
        }

        public void DebugStack()
        {
            StringBuilder sBuilder = new StringBuilder();

            sBuilder.AppendLine($"STACK");
            foreach (var item in BackStack)
            { 
                sBuilder.AppendLine($"{item.UIBase} {item.UIEventType} {item.Type}");
            }

            UnityEngine.Debug.Log(sBuilder.ToString());     
        }
    }
}
